#include "Config.h"
#include "TestBase.h"

TestBase::TestBase()
{
	info.Name = "Config system test 1";
	info.Category = 0x1101;
	info.CategoryName = "Config system tests";
	info.File = __FILE__;
}

void PrintFail(ITest* test, std::string v, std::string eV)
{
	fprintf(stderr, "%s failure info\n", test->GetTestInfo()->Name.c_str());
	fprintf(stderr, "Output          : %s\n", v.c_str());
	fprintf(stderr, "Expected output : %s\n", eV.c_str());
	fprintf(stderr, "Same?           : %s\n", (v == eV) ? "true" : "false");
}

bool TestBase::Run()
{
	std::string file = "TestModules/ConfigTest1.conf";
	std::string eV[] = {
		"12.45E3",
		"im another string",
		"123",
		"i have a \" in me",
	};
	std::string value;
	if (!conf.ParseConfigFile(file))
	{
		return false;
	}
	value = conf.GetValue("test1");
	if (value != eV[0])
	{
		PrintFail(this, value, eV[0]);
		return false;
	}
	value = conf.GetValue("test2");
	if (value != eV[1])
	{
		PrintFail(this, value, eV[1]);
		return false;
	}
	value = conf.GetValue("test3");
	if (value != eV[2])
	{
		PrintFail(this, value, eV[2]);
		return false;
	}
	value = conf.GetValue("test4");
	if (value != eV[3])
	{
		PrintFail(this, value, eV[3]);
		return false;
	}
	return true;
}